#ifndef APPSINGLETON_H
#define APPSINGLETON_H
#include <QApplication>
#include <QWidget>
#include <QList>
#include <QPointer>
#include "core_global.h"
template<typename T>
class CORE_EXPORT CAppSingleton
{
public:
    static CAppSingleton<T>* GetInstance()
    {
        static CAppSingleton<T> instance;
        return &instance;
    }

    void AddObject(T* object)
    {
        if (object != nullptr && !m_objects.contains(object))
        {
            m_objects.append(object);
        }
    }

    // [FDD-2025-03-021][API-002] Remove object from singleton list
    bool RemoveObject(T* object)
    {
        if (object == nullptr) {
            return false;
        }
        return m_objects.removeOne(object);
    }

    const QList<T*>& GetAllObjects() const
    {
        return m_objects;
    }

protected:
    CAppSingleton() = default;
    ~CAppSingleton() = default;

private:
    QList<T*> m_objects;
};



#endif // APPSINGLETON_H
